<div class="am-g">
    <!-- Row start -->
    <div class="am-u-sm-12">
        <form action="" class="am-form" data-am-validator id="doc-vld-msg">
            <div class="card-box">

                <fieldset>
                    <div class="am-form-group am-form-group-sm">
                        <label for="doc-vld-name-2">销售主题：</label>
                        <input type="text" name="name" class="am-form-field" id="fname" placeholder="销售主题" />
                    </div>
                    <div class="am-form-group">
                        <label>订单状态： </label>
                        <label class="am-radio-inline">
								        <input type="radio"  value="0" name="state"> 未付款
								      </label>
                        <label class="am-radio-inline">
								        <input type="radio"  value="1" name="state"> 已付款
								      </label>
                    </div>
                    <div class="am-form-group">
                        <div class="am-g">
                            <label class="am-u-md-2 am-md-text-right" for="doc-select-1">采购商</label>
                            <select id="doc-select-1" name="partner" id="pids">
                                {{range .cl}}
                                <option value="{{.Id}}">{{.Name}}</option>
                                {{end}}
                            </select>
                            <span class="am-form-caret"></span>
                        </div>
                    </div>

                    <!-- 省 市 县区 select 稍后添加上去-->
                    <div class="am-form-group am-form-group-sm">
                        <label for="doc-vld-name-2">详细地址：</label>
                        <input type="text" name="street" class="am-form-field" id="street" placeholder="详细地址" />
                         </div>
                    <button class="am-btn am-btn-secondary" type="button">提交</button> &nbsp;&nbsp;&nbsp;&nbsp;总价：<span id="showprice">0.00</span>

                </fieldset>

            </div>
            <div class="am-scrollable-horizontal">
                <table class="am-table am-table-striped am-table-hover table-main am-text-nowrap">
                    <input id="zprice-num" style="display:none" name="zprice" value="0.00">
                    <thead>
                        <tr>
                            <th class="table-id">名称</th>
                            <th class="table-title">单位</th>
                            <th class="table-title">数量</th>
                            <th class="table-title">编码</th>
                            <th class="table-title">价格</th>
                            <th class="table-title">规格</th>
                            <th class="table-title">型号</th>
                            <th class="table-title">分类</th>
                            <th class="table-title">状态</th>
                            <th class="table-title">销售状态</th>
                            <th class="table-type">添加时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{range .glist}}
                        <tr>
                            <td>{{.Name}}</td>
                            <td>{{.Units}}</td>
                            <td>
                                <input style="display:none" name="goods[]" class="am-form-field" value="{{.Id}}">
                                <input style="width:100px" data-zprice="{{.Price}}" name="GoodsNum[]" class="am-form-field" value="1">
                            </td>
                            <td>{{.Gcode}}</td>
                            <td>{{.Price}}</td>
                            <td>{{.Spec}}</td>
                            <td>{{.Gmodel}}</td>
                            <td>{{.Sname}}</td>
                            <td>{{.Status}}</td>
                            <td>{{.SaleStatus}}</td>
                            <td>{{timetodateint64 .Ctime}}</td>
                        </tr>
                        {{end}}
                    </tbody>
                </table>
            </div>
        </form>
    </div>
    <!-- Row end -->
</div>
</div>
</div>
<script>
    var _url = "/sale/add"
    $(document).ready(function(){
        var _zprice=0.00
        $("tbody tr").each(function(){
            var dd=$(this).find("td").eq(2).find("input").eq(1)
            console.log(dd)
            _zprice=_zprice+dd.val()*dd.attr("data-zprice");
        });
        $("#showprice").html(_zprice);
        $("#zprice-num").val(_zprice);
    });
    $("tbody tr td input").blur(function(){
                var _zprice=0.00
            $("tbody tr").each(function(){
                var dd=$(this).find("td").eq(2).find("input").eq(1)
                console.log(dd)
                _zprice=_zprice+dd.val()*dd.attr("data-zprice");
            });
            $("#showprice").html(_zprice);
            $("#zprice-num").val(_zprice);
    });

    $(".am-btn").on("click", function () {
        var name = $("#fname").val();
        if (name.length < 1) {
            alert("分类名称不能为空！")
            return
        }
        //计算一次总价

        $.post(_url, $("form").serializeArray(), function (data) {
            if (data.status == 1) {
                alert("添加成功")
                window.location.href = data.url
            } else {
                alert(data.msg);
            }
        }, "json");
    });

</script>